<?php

namespace plugins\yifang_backend_account\client\admin;

use app\utils\contract\Backend_account;

class C_rbac
{
    /**
     * 获取菜单数据
     * @param string $paramObj
     */
    public function menuData($paramObj=""){
        $uid=app(Backend_account::class)->getLoginData()["id"];
        $paramsObj=paramsObj();
        $paramsObj->mixed=1;
        $paramsObj->params=array(
            "uid"=>$uid,
        );
        $paramsObj=blenderObject($paramsObj,$paramObj);
        $checkResult=app("YifangBackendAccount_L_Admin_rbac")->menuData($paramsObj);
        if($checkResult["error_no"]==0){
            return $checkResult["result"];
        }else{
            recordErrorLog($checkResult); //记录错误信息
            return array();
        }
    }

    /**
     * 权限列表
     * @param string $paramObj
     */
    public function permissionList($paramObj=""){
        $paramsObj=paramsObj();
        $paramsObj->mixed=1;
        $paramsObj=blenderObject($paramsObj,$paramObj);
        $checkResult=app("YifangBackendAccount_L_Admin_rbac")->permissionList($paramsObj);
        if($checkResult["error_no"]==0){
            return $checkResult["result"];
        }else{
            recordErrorLog($checkResult); //记录错误信息
            return array();
        }
    }

    /**
     * 初始化节点
     * @param string $paramObj
     */
    public function initNode($paramObj=""){
        $paramsObj=paramsObj();
        $paramsObj->mixed=1;
        $paramsObj=blenderObject($paramsObj,$paramObj);
        $checkResult=app("YifangBackendAccount_L_Admin_rbac")->initNode($paramsObj);
        if($checkResult["error_no"]==0){
            return apiResult(true,"success",0,$checkResult["result"],$checkResult["extra"]);
        }else{
            recordErrorLog($checkResult); //记录错误信息
            return apiResult(false,$checkResult["error_msg"],$checkResult["error_no"]);
        }
    }

    /**
     * 初始化数据
     * @param string $paramObj
     */
    public function initData($paramObj=""){
        $paramsObj=paramsObj();
        $paramsObj->mixed=1;
        $paramsObj=blenderObject($paramsObj,$paramObj);
        $checkResult=app("YifangBackendAccount_L_Admin_rbac")->initData($paramsObj);
        if($checkResult["error_no"]==0){
            return apiResult(true,"success",0,$checkResult["result"],$checkResult["extra"]);
        }else{
            recordErrorLog($checkResult); //记录错误信息
            return apiResult(false,$checkResult["error_msg"],$checkResult["error_no"]);
        }
    }
}